package middol.utils

import groovy.transform.CompileStatic
import middol.config.NoticeConfig
import middol.notice.IMessage
import middol.notice.INoticeHandler
import middol.notice.NoticeHandlerContext
import middol.notice.NoticeHandlerFactory
import org.springframework.beans.factory.annotation.Autowired

/**
* @Description:    通知工具类
* @Author:         zhangjiayu@middol.com
* @CreateDate:     2020/10/21 10:43
* @Version:        1.0
*/
@CompileStatic
class NoticeService {
    @Autowired
    NoticeHandlerContext noticeHandlerContext
    @Autowired
    NoticeConfig noticeConfig

    /**
     * send notice
     * @param message
     */
    void sendNotice(IMessage message){
        INoticeHandler noticeHandler = NoticeHandlerFactory.getNoticeHandler(noticeConfig?.type ?: message?.type)
        noticeHandlerContext.setNoticeHandler(noticeHandler)
        noticeHandlerContext.handleSend(message)
    }
}
